package bar.dark.lee.setting.sms;

import java.math.BigDecimal;
import java.util.HashMap;

import android.content.Context;
import android.database.Cursor;
import android.widget.Toast;
import bar.dark.lee.BDConstents;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.common.DBSQLite;
import bar.dark.lee.common.DBSQLite.ParseSelectData;

public class SMSInsertDB {
	
	private int linkId;
	
	private boolean flag = false;
	
	private int smsType;
	
	
	public boolean bankInInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT id, money FROM bankbook WHERE name = '" + 
									BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
//				int tempMoney = money;
				BigDecimal tempMoney = money;
				
				int idIndex = c.getColumnIndex("id");
				int moneyIndex = c.getColumnIndex("money");
				
				c.moveToFirst();
				BigDecimal dbMoney = BigDecimal.ZERO;
				int id = -1;
				
				if (c.getCount() != 0)
				{
					for (int i = 0; i < c.getCount(); i++)
					{
						id = c.getInt(idIndex);
//						tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
						dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
						c.moveToNext();
					}
					
					//dbMoney = dbMoney.subtract(tempMoney);
					dbMoney = dbMoney.add(tempMoney);
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("money", dbMoney.toString());
					String [] whereArgs = new String[]{id+ ""};
					sql.update(context, "bankbook", map, "id = ?", whereArgs);
					
					smsType = BDConstents.IN_SMS;
					
					setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
					
					flag = true;
				}
				else
				{
					//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		return flag;
	}
	
	public boolean bankInAtmInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT id, money FROM bankbook WHERE name = '" + 
									BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
//				int tempMoney = money;
				BigDecimal tempMoney = money;
				
				int idIndex = c.getColumnIndex("id");
				int moneyIndex = c.getColumnIndex("money");
				
				c.moveToFirst();
				BigDecimal dbMoney = BigDecimal.ZERO;
				int id = -1;
				
				if (c.getCount() != 0)
				{
					for (int i = 0; i < c.getCount(); i++)
					{
						id = c.getInt(idIndex);
//						tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
						dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
						c.moveToNext();
					}
					
					//dbMoney = dbMoney.subtract(tempMoney);
					dbMoney = dbMoney.add(tempMoney);
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("money", dbMoney.toString());
					String [] whereArgs = new String[]{id+ ""};
					sql.update(context, "bankbook", map, "id = ?", whereArgs);
					
					smsType = BDConstents.IN_ATM_SMS;
					
					flag = true;
				}
				else
				{
					//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		if (flag == true)
		{
			sql.selectMapTile(context, "SELECT id, money FROM real_money;", new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
//					int tempMoney = money;
					BigDecimal tempMoney = money;
					
					int idIndex = c.getColumnIndex("id");
					int moneyIndex = c.getColumnIndex("money");
					
					c.moveToFirst();
					BigDecimal dbMoney = BigDecimal.ZERO;
					int id = -1;
					
					if (c.getCount() != 0)
					{
						for (int i = 0; i < c.getCount(); i++)
						{
							id = c.getInt(idIndex);
//							tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
							dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
							c.moveToNext();
						}
						
						//dbMoney = dbMoney.subtract(tempMoney);
						dbMoney = dbMoney.subtract(tempMoney);
						
						HashMap<String, String> map = new HashMap<String, String>();
						map.put("money", dbMoney.toString());
						String [] whereArgs = new String[]{id+ ""};
						sql.update(context, "real_money", map, "id = ?", whereArgs);
						
						smsType = BDConstents.IN_ATM_SMS;
						
						setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
						
						flag = true;
					}
					else
					{
						//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
						flag = false;
					}
				}
			});
		}
		
		return flag;
	}
	
	public boolean bankOutInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT id, money FROM bankbook WHERE name = '" + 
									BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
//				int tempMoney = money;
				BigDecimal tempMoney = money;
				
				int idIndex = c.getColumnIndex("id");
				int moneyIndex = c.getColumnIndex("money");
				
				c.moveToFirst();
				BigDecimal dbMoney = BigDecimal.ZERO;
				int id = -1;
				
				if (c.getCount() != 0)
				{
					for (int i = 0; i < c.getCount(); i++)
					{
						id = c.getInt(idIndex);
//						tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
						dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
						c.moveToNext();
					}
					
					dbMoney = dbMoney.subtract(tempMoney);
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("money", dbMoney.toString());
//					String [] whereArgs = new String[]{linkId + ""};
					String [] whereArgs = new String[]{id + ""};
					sql.update(context, "bankbook", map, "id = ?", whereArgs);
					
					smsType = BDConstents.OUT_SMS;
					
					setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
					
					flag = true;
				}
				else
				{
					//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});		
		
		return flag;
	}
	
	public boolean bankOutAtmInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT id, money FROM bankbook WHERE name = '" + 
									BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
//				int tempMoney = money;
				BigDecimal tempMoney = money;
				
				int idIndex = c.getColumnIndex("id");
				int moneyIndex = c.getColumnIndex("money");
				
				c.moveToFirst();
				BigDecimal dbMoney = BigDecimal.ZERO;
				int id = -1;
				
				if (c.getCount() != 0)
				{
					for (int i = 0; i < c.getCount(); i++)
					{
						id = c.getInt(idIndex);
//						tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
						dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
						c.moveToNext();
					}
					
					//dbMoney = dbMoney.subtract(tempMoney);
					dbMoney = dbMoney.subtract(tempMoney);
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("money", dbMoney.toString());
					String [] whereArgs = new String[]{id+ ""};
					sql.update(context, "bankbook", map, "id = ?", whereArgs);
					
					smsType = BDConstents.IN_ATM_SMS;
					
					flag = true;
				}
				else
				{
					//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		if (flag == true)
		{
			sql.selectMapTile(context, "SELECT id, money FROM real_money;", new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
//					int tempMoney = money;
					BigDecimal tempMoney = money;
					
					int idIndex = c.getColumnIndex("id");
					int moneyIndex = c.getColumnIndex("money");
					
					c.moveToFirst();
					BigDecimal dbMoney = BigDecimal.ZERO;
					int id = -1;
					
					if (c.getCount() != 0)
					{
						for (int i = 0; i < c.getCount(); i++)
						{
							id = c.getInt(idIndex);
//							tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
							dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
							c.moveToNext();
						}
						
						//dbMoney = dbMoney.subtract(tempMoney);
						dbMoney = dbMoney.add(tempMoney);
						
						HashMap<String, String> map = new HashMap<String, String>();
						map.put("money", dbMoney.toString());
						String [] whereArgs = new String[]{id+ ""};
						sql.update(context, "real_money", map, "id = ?", whereArgs);
						
						smsType = BDConstents.OUT_ATM_SMS;
						
						setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
						
						flag = true;
					}
					else
					{
						//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
						flag = false;
					}
				}
			});
		}
		
		return flag;
	}
	
	public boolean checkInInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT banklink FROM check_card WHERE name = '" 
				+ BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int banklinkIndex = c.getColumnIndex("banklink");
				
				linkId = -1;
				flag = false;
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					linkId = c.getInt(banklinkIndex);
					c.moveToNext();
				}
				
				if (linkId > -1)
				{
					sql.selectMapTile(context, "SELECT money FROM bankbook WHERE id = " + linkId, new ParseSelectData()
					{
						@Override
						public void resultData(Cursor c)
						{
//							int tempMoney = money;
							BigDecimal tempMoney = money;
							
							int moneyIndex = c.getColumnIndex("money");
							
							c.moveToFirst();
							BigDecimal dbMoney = BigDecimal.ZERO;
							for (int i = 0; i < c.getCount(); i++)
							{
//								tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
								dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
								c.moveToNext();
							}
							
							//dbMoney = dbMoney.subtract(tempMoney);
							dbMoney = dbMoney.add(tempMoney);
							
							HashMap<String, String> map = new HashMap<String, String>();
							map.put("money", dbMoney.toString());
							String [] whereArgs = new String[]{linkId + ""};
							sql.update(context, "bankbook", map, "id = ?", whereArgs);
							
							smsType = BDConstents.IN_SMS;
							
							setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
							
							flag = true;
						}
					});
				}
				else
				{
					//BDUtil.showToast(context, "체크카드가  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		return flag;
	}
	
	public boolean checkInAtmInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT banklink FROM check_card WHERE name = '" 
				+ BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int banklinkIndex = c.getColumnIndex("banklink");
				
				linkId = -1;
				flag = false;
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					linkId = c.getInt(banklinkIndex);
					c.moveToNext();
				}
				
				if (linkId > -1)
				{
					sql.selectMapTile(context, "SELECT money FROM bankbook WHERE id = " + linkId, new ParseSelectData()
					{
						@Override
						public void resultData(Cursor c)
						{
//							int tempMoney = money;
							BigDecimal tempMoney = money;
							
							int moneyIndex = c.getColumnIndex("money");
							
							c.moveToFirst();
							BigDecimal dbMoney = BigDecimal.ZERO;
							for (int i = 0; i < c.getCount(); i++)
							{
//								tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
								dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
								c.moveToNext();
							}
							
							//dbMoney = dbMoney.subtract(tempMoney);
							dbMoney = dbMoney.add(tempMoney);
							
							HashMap<String, String> map = new HashMap<String, String>();
							map.put("money", dbMoney.toString());
							String [] whereArgs = new String[]{linkId + ""};
							sql.update(context, "bankbook", map, "id = ?", whereArgs);
							
							smsType = BDConstents.IN_ATM_SMS;
							
							flag = true;
						}
					});
				}
				else
				{
					//BDUtil.showToast(context, "체크카드가  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		if (flag == true)
		{
			sql.selectMapTile(context, "SELECT id, money FROM real_money;", new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
//					int tempMoney = money;
					BigDecimal tempMoney = money;
					
					int idIndex = c.getColumnIndex("id");
					int moneyIndex = c.getColumnIndex("money");
					
					c.moveToFirst();
					BigDecimal dbMoney = BigDecimal.ZERO;
					int id = -1;
					
					if (c.getCount() != 0)
					{
						for (int i = 0; i < c.getCount(); i++)
						{
							id = c.getInt(idIndex);
//							tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
							dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
							c.moveToNext();
						}
						
						//dbMoney = dbMoney.subtract(tempMoney);
						dbMoney = dbMoney.subtract(tempMoney);
						
						HashMap<String, String> map = new HashMap<String, String>();
						map.put("money", dbMoney.toString());
						String [] whereArgs = new String[]{id+ ""};
						sql.update(context, "real_money", map, "id = ?", whereArgs);
						
						smsType = BDConstents.IN_ATM_SMS;
						
						setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
						
						flag = true;
					}
					else
					{
						//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
						flag = false;
					}
				}
			});
		}
		
		return flag;
	}
	
	public boolean checkOutInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT banklink FROM check_card WHERE name = '" 
				+ BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int banklinkIndex = c.getColumnIndex("banklink");
				
				linkId = -1;
				flag = false;
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					linkId = c.getInt(banklinkIndex);
					c.moveToNext();
				}
				
				if (linkId > -1)
				{
					sql.selectMapTile(context, "SELECT money FROM bankbook WHERE id = " + linkId, new ParseSelectData()
					{
						@Override
						public void resultData(Cursor c)
						{
//							int tempMoney = money;
							BigDecimal tempMoney = money;
							
							int moneyIndex = c.getColumnIndex("money");
							
							c.moveToFirst();
							BigDecimal dbMoney = BigDecimal.ZERO;
							for (int i = 0; i < c.getCount(); i++)
							{
//								tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
								dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
								c.moveToNext();
							}
							
							dbMoney = dbMoney.subtract(tempMoney);
							
							HashMap<String, String> map = new HashMap<String, String>();
							map.put("money", dbMoney.toString());
							String [] whereArgs = new String[]{linkId + ""};
							sql.update(context, "bankbook", map, "id = ?", whereArgs);
							
							smsType = BDConstents.OUT_SMS;
							
							setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
							
							flag = true;
						}
					});
				}
				else
				{
					//BDUtil.showToast(context, "체크카드가  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		return flag;
	}
	
	public boolean checkOutAtmInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT banklink FROM check_card WHERE name = '" 
				+ BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int banklinkIndex = c.getColumnIndex("banklink");
				
				linkId = -1;
				flag = false;
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					linkId = c.getInt(banklinkIndex);
					c.moveToNext();
				}
				
				if (linkId > -1)
				{
					sql.selectMapTile(context, "SELECT money FROM bankbook WHERE id = " + linkId, new ParseSelectData()
					{
						@Override
						public void resultData(Cursor c)
						{
//							int tempMoney = money;
							BigDecimal tempMoney = money;
							
							int moneyIndex = c.getColumnIndex("money");
							
							c.moveToFirst();
							BigDecimal dbMoney = BigDecimal.ZERO;
							for (int i = 0; i < c.getCount(); i++)
							{
//								tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
								dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
								c.moveToNext();
							}
							
							dbMoney = dbMoney.subtract(tempMoney);
							
							HashMap<String, String> map = new HashMap<String, String>();
							map.put("money", dbMoney.toString());
							String [] whereArgs = new String[]{linkId + ""};
							sql.update(context, "bankbook", map, "id = ?", whereArgs);
							
							smsType = BDConstents.OUT_ATM_SMS;
							
							flag = true;
						}
					});
				}
				else
				{
					//BDUtil.showToast(context, "체크카드가  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		if (flag == true)
		{
			sql.selectMapTile(context, "SELECT id, money FROM real_money;", new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
//					int tempMoney = money;
					BigDecimal tempMoney = money;
					
					int idIndex = c.getColumnIndex("id");
					int moneyIndex = c.getColumnIndex("money");
					
					c.moveToFirst();
					BigDecimal dbMoney = BigDecimal.ZERO;
					int id = -1;
					
					if (c.getCount() != 0)
					{
						for (int i = 0; i < c.getCount(); i++)
						{
							id = c.getInt(idIndex);
//							tempMoney = Integer.parseInt(c.getString(moneyIndex)) - tempMoney;
							dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
							c.moveToNext();
						}
						
						//dbMoney = dbMoney.subtract(tempMoney);
						dbMoney = dbMoney.add(tempMoney);
						
						HashMap<String, String> map = new HashMap<String, String>();
						map.put("money", dbMoney.toString());
						String [] whereArgs = new String[]{id+ ""};
						sql.update(context, "real_money", map, "id = ?", whereArgs);
						
						smsType = BDConstents.OUT_ATM_SMS;
						
						setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
						
						flag = true;
					}
					else
					{
						//BDUtil.showToast(context, "통장이  없어서 입력에 실패했습니다.");
						flag = false;
					}
				}
			});
		}
		
		return flag;
	}
	
	public boolean creditOutInsert(final Context context, final DBSQLite sql, final String linkCardType, final String cardName,
			final String date, final BigDecimal money, final String memo, final String category)
	{
		sql.selectMapTile(context, "SELECT id, outmoney FROM credit_card WHERE name = '" 
				+ BDUtil.getApostrophe(cardName) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
//				int tempMoney = money;
				BigDecimal tempMoney = money;
				int id = -1;
				int idIndex = c.getColumnIndex("id");
				int moneyIndex = c.getColumnIndex("outmoney");
				
				c.moveToFirst();
				BigDecimal dbMoney = BigDecimal.ZERO;
				for (int i = 0; i < c.getCount(); i++)
				{
					id = c.getInt(idIndex);
//					tempMoney = Integer.parseInt(c.getString(moneyIndex)) + tempMoney;
					dbMoney = dbMoney.add(new BigDecimal(c.getString(moneyIndex)));
					c.moveToNext();
				}
				
				dbMoney = dbMoney.add(tempMoney);
				
				if (id > 0)
				{
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("outmoney", dbMoney.toString());
					String [] whereArgs = new String[]{id + ""};
					sql.update(context, "credit_card", map, "id = ?", whereArgs);
					
					smsType = BDConstents.OUT_SMS;
					
					setInOutTable(context, sql, cardName, linkCardType, date, money, memo, category);
					
					flag = true;
				}
				else
				{
					//BDUtil.showToast(context, "신용카드가  없어서 입력에 실패했습니다.");
					flag = false;
				}
			}
		});
		
		return flag;
	}
	
	public void setInOutTable(Context context, DBSQLite sql, String moneyKind, String type, 
							String date, BigDecimal money, String memo, String category)
	{
		try 
		{
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("category", "");
			
			if (type.equals("3"))
			{
				map.put("postmoney", money.toString());
				if (category == null || category.equalsIgnoreCase(""))
				{
					map.put("category", BDConstents.CATEGORY_USE_CARD);
				}
				else
				{
					map.put("category", category);
				}
				//type = "3";
				type = BDConstents.CREDIT_TYPE;
			}
			else if (type.equals("4"))
			{
				if (smsType == BDConstents.IN_SMS)
				{
					map.put("inmoney", money.toString());
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_IN_CARD);
					}
					else
					{
						map.put("category", category);
					}
					//type = "2";
					type = BDConstents.CHECK_TYPE;
				}
				else if (smsType == BDConstents.OUT_SMS)
				{
					map.put("outmoney", money.toString());
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_USE_CARD);
					}
					else
					{
						map.put("category", category);
					}
					//type = "2";
					type = BDConstents.CHECK_TYPE;
				}
				else if (smsType == BDConstents.IN_ATM_SMS)
				{
					map.put("inmoney", money.toString());
					map.put("outmoney", money.toString());
					map.put("linktype", BDConstents.CHECK_TYPE);
					map.put("linkid", -1+"");
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_IN_CARD);
					}
					else
					{
						map.put("category", category);
					}
					//type = "6";
					type = BDConstents.OUTIN_TYPE;
				}
				else if (smsType == BDConstents.OUT_ATM_SMS)
				{
					map.put("inmoney", money.toString());
					map.put("outmoney", money.toString());
					map.put("linktype", BDConstents.CHECK_TYPE);
					map.put("linkid", -1+"");
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_OUT_CARD);
					}
					else
					{
						map.put("category", category);
					}
					//type = "4";
					type = BDConstents.INOUT_TYPE;
				}
			}
			else if (type.equals("1"))
			{
				if (smsType == BDConstents.IN_SMS)
				{
					map.put("inmoney", money.toString());
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_IN_BANK);
					}
					else
					{
						map.put("category", category);
					}
					//type = "1";
					type = BDConstents.BANK_TYPE;
				}
				else if (smsType == BDConstents.OUT_SMS)
				{
					map.put("outmoney", money.toString());
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_OUT_BANK);
					}
					else
					{
						map.put("category", category);
					}
					//type = "1";
					type = BDConstents.BANK_TYPE;
				}
				else if (smsType == BDConstents.IN_ATM_SMS)
				{
					map.put("inmoney", money.toString());
					map.put("outmoney", money.toString());
					map.put("linktype", BDConstents.BANK_TYPE);
					map.put("linkid", -1+"");
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_IN_BANK);
					}
					else
					{
						map.put("category", category);
					}
					//type = "6";
					type = BDConstents.OUTIN_TYPE;
				}
				else if (smsType == BDConstents.OUT_ATM_SMS)
				{
					map.put("inmoney", money.toString());
					map.put("outmoney", money.toString());
					map.put("linktype", BDConstents.BANK_TYPE);
					map.put("linkid", -1+"");
					if (category == null || category.equalsIgnoreCase(""))
					{
						map.put("category", BDConstents.CATEGORY_OUT_BANK);
					}
					else
					{
						map.put("category", category);
					}
					//type = "4";
					type = BDConstents.INOUT_TYPE;
				}
			}
			
			date = date.replace(" ", "");
			date = date.replace("-", "");
			map.put("date", date);
			map.put("moneykind", moneyKind);
			map.put("type", type);
			map.put("memo", memo);
			
			sql.insert(context, map, "in_out");
		}
		catch (Exception e)
		{
//			Toast.makeText(context, "죄송합니다. 입력에 실패했습니다. " +
//					"문자 자동화 등록에 문제가 있는 것으로 판단되오니 " +
//					"해당 문자로 개발자에게 문의주세요ㅠ", Toast.LENGTH_LONG).show();
		}
		
	}
}
